/*
 * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package com.amazonaws.services.iot.client.sample.pubSub;

import com.amazonaws.services.iot.client.AWSIotMessage;
import com.amazonaws.services.iot.client.AWSIotQos;
import com.amazonaws.services.iot.client.AWSIotTopic;

import io.goeasy.GoEasy;


/**
 * This class extends {@link AWSIotTopic} to receive messages from a subscribed
 * topic.
 */
public class TestTopicListener extends AWSIotTopic {
	
	String getTheMessage;

    public TestTopicListener(String topic, AWSIotQos qos) {
        super(topic, qos);
    }

    @Override
    public void onMessage(AWSIotMessage message) {
    	
    	 getTheMessage = message.getStringPayload();
    	 GoEasy goEasy = new GoEasy("BC-f35922c037c14ad78a55d27de46e3a59");
 		 goEasy.publish("goeasy_iot",message.getStringPayload());
 		 Thread mythread = new Thread(new Thread1());
 		 mythread.start();
        System.out.println(System.currentTimeMillis() + ": <<< " + message.getStringPayload());
    }
    
    public class Thread1 implements Runnable {
    	
 	   public void run() {  
 	       {
 	    	     SendMail sendMail = new SendMail();
 	    		 int temperature = sendMail.token(getTheMessage);
 	    		 try{
 	    			 if(temperature == 50) {
 	    				 sendMail.send();
 	    			 }
 	          	 
 	    		 }catch(Exception e){
 	          	
 	    			 System.out.println("#####################################");
 	    		 }
 	 
 	       }
 	   }
 	}
    
  
 

 

}
